package QianFeng07.IODemo;

import java.io.*;

/**
 * 打印流
 * 打印流的主要功能是用于输出，在整个I0包中打印流分为两种类型:
 * 字节打印流: PrintStream
 * 字符打印流:T PrintWriter
 * 打印流可以很方便的进行输出
 **/
public class PrintStreamDemo {
    public static void main(String[] args) {
        //bytePrintStream();
        charPrintWriter();
    }
    //字节打印流
    private static void bytePrintStream() {
        File file = new File("F:\\Test\\Test.txt");
        try {
            //字节输出流
            OutputStream outputStream = new FileOutputStream(file);
            //加缓存流 提高效率
            BufferedOutputStream bos = new BufferedOutputStream(outputStream);
            //加打印流 增强打印功能
            PrintStream printStream = new PrintStream(bos);
            printStream.println("小河流水依然哗啦啦");
            printStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    //字符打印流
    private static void charPrintWriter() {
        File file = new File("F:\\Test\\Test.txt");
        try {
            //字符输出流
            Writer writer = new FileWriter(file);
            //加缓存流 提高效率
            BufferedWriter bw = new BufferedWriter(writer);
            //加打印流 增强打印功能
            PrintWriter printWriter = new PrintWriter(bw);
            printWriter.println("小河流水依然哗啦啦");
            printWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
